package com.evon.yardmanagement.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "COMPANY")
@Access(AccessType.FIELD)
@AttributeOverride( name="id", column = @Column(name="COMPANY_ID") )
public class Vendor extends BaseModel implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Column(name = "COMPANY_NAME")
	private String name;

	

	@Column(name = "ADDRESS")
	private String address;
	@Column(name = "CITY")
	private String city;

	@Column(name = "PHONE")
	private String phone;

	@Column(name = "EMAIL")
	private String email;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "owningCompany")
	private Set<Role> availableRoles = new HashSet(0);
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Yard.class)
	  @JoinTable(name = "YARD_MAPPING",
	    joinColumns = {
	      @JoinColumn(name="COMPANY_ID", unique = true)           
	    },
	    inverseJoinColumns = {
	      @JoinColumn(name="YARD_ID")
	    }
	  )
    private Set<Yard> availableYards = new HashSet(0);
	@Transient
    private Set availableUsers = new HashSet(0);
    
	@ManyToOne
	@JoinColumn(name = "STATE_ID")
	private State state;
	
	@Column(name="STATUS")
	private int isActive;

	@Column(name="ZIP")
	private String zipCode;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Set getAvailableRoles() {
		return availableRoles;
	}

	public void setAvailableRoles(Set availableRoles) {
		this.availableRoles = availableRoles;
	}

	public Set getAvailableYards() {
		return availableYards;
	}

	public void setAvailableYards(Set availableYards) {
		this.availableYards = availableYards;
	}

	public Set getAvailableUsers() {
		return availableUsers;
	}

	public void setAvailableUsers(Set availableUsers) {
		this.availableUsers = availableUsers;
	}

	/**
	 * 
	 * @return all the yards belonging to this company
	 */

	 
	public Set<Yard> getYards() {
		return availableYards;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	

	public int getIsActive() {
		return isActive;
	}

	public void setIsActive(int isActive) {
		this.isActive = isActive;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

}
